import 'dart:math';

import 'package:flutter/material.dart';

class SizeConfig {
  static MediaQueryData _mediaQueryData;
  static double screenWidth;
  static double screenHeight;
  static double defaultSize;
  static Orientation orientation;

  void init(BuildContext context) {
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData.size.width;
    screenHeight = _mediaQueryData.size.height;
    orientation = _mediaQueryData.orientation;
  }
}

// Get the proportionate height as per screen size
double getPortraitSHeight(double inputHeight) {
  double screenHeight = SizeConfig.screenHeight;
  // 812 is the layout height that designer use
  return (inputHeight / 667.0) * screenHeight;
}

// Get the proportionate height as per screen size
double getPortraitSWidth(double inputWidth) {
  double screenWidth = SizeConfig.screenWidth;
  // 375 is the layout width that designer use
  return (inputWidth / 375.0) * screenWidth;
}
Size uiSize=Size(375,667);
/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double get scaleWidth => SizeConfig.screenWidth / uiSize.width;

///  /// The ratio of actual height to UI design
double get scaleHeight => SizeConfig.screenHeight / uiSize.height;

double get scaleText => min(scaleWidth, scaleHeight);
//根据宽度或高度中的较小值进行适配
///Adapt according to the smaller of width or height
double radius(num r) => r * scaleText;

///字体大小适配方法
///- [fontSize] UI设计上字体的大小,单位dp.
///Font size adaptation method
///- [fontSize] The size of the font on the UI design, in dp.
double setSp(num fontSize) => fontSize * scaleText;